package com.bjbn.controller;

import com.alibaba.fastjson.JSONObject;
import com.bjbn.bean.ApiCallParams;
import com.bjbn.bean.ApiResult;
import com.bjbn.service.DataphinService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/dataphin")
@Slf4j
public class DataphinApiController {

    @Autowired
    DataphinService dataphinService;


    @RequestMapping("/data_twin_s_ias_historycraftsiteallcocate")
    public JSONObject s_ias_historycraftsiteallcocate(@RequestParam(required = false, defaultValue = "") String orderByList,
                                                      @RequestParam(required = false, defaultValue = "1") Integer pageStart,
                                                      @RequestParam(required = false, defaultValue = "20") Integer pageSize) {
        String fields = "id,flightid,craftsite,starttime,endtime,startrealtime,endrealtime,ordercode";
        ApiCallParams apiCallParams = new ApiCallParams();
        apiCallParams.setApiId("10353");
        apiCallParams.setApiType("LIST");
        apiCallParams.setAppKey("200000226");
        apiCallParams.setAppSecret("d43bc101cb3b4add8554f821b568c84c");
        apiCallParams.setApiReturnFields(fields);
        apiCallParams.setListType("LIST");
        apiCallParams.setPageStart(pageStart);
        apiCallParams.setPageSize(pageSize);
        apiCallParams.setOrderByList(orderByList);
        ApiResult apiResult = dataphinService.getDataphinData(apiCallParams);

        if (apiResult.getResultCode() == 200) {
            return JSONObject.parseObject(apiResult.getResultBody());
        } else {
            return JSONObject.parseObject(apiResult.getError());
        }
    }
}
